package cn.edu.fzu.homemaking.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.*;

import cn.edu.fzu.homemaking.api.SsoApi;
import cn.edu.fzu.homemaking.domain.enums.SexEnum;
import cn.edu.fzu.homemaking.domain.enums.StatusEnum;
import cn.edu.fzu.homemaking.web.Result;
import io.swagger.annotations.*;

@Api(tags = "sys-系统用户管理")
@RestController
@RequestMapping("/api/sys")
public class SysUserController {

    @Resource
    private SsoApi ssoApi;

    @ApiOperation(value = "获取当前用户信息", httpMethod = "GET")
    @ApiResponse(code = 200, message = "", response = Result.class)
    @GetMapping("/auth/myInfo")
    public Result getInfo() {
        Result info = ssoApi.getUserInfo();
        return info;
    }


    @ApiOperation(value = "获取系统用户列表", httpMethod = "GET")
    @ApiResponse(code = 200, message = "", response = Result.class)
    @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", required = true, value = "页码"),
            @ApiImplicitParam(name = "pageSize", required = true, value = "页面大小"),
            @ApiImplicitParam(name = "email", required = false, value = "邮箱"),
            @ApiImplicitParam(name = "name", required = false, value = "名字"),
            @ApiImplicitParam(name = "sex", required = false, value = "-1-保密，0-男，1-女"),
            @ApiImplicitParam(name = "status", required = false, value = "-1-删除，0-禁用，1-正常") })
    @GetMapping("auth/sysuser/list")
    @ResponseBody
    public Result list(String name, String email, SexEnum sex, String phone, StatusEnum status, Integer pageNum,
                       Integer pageSize, HttpServletRequest request) {
        Result result = ssoApi.listSysUser(email, name, sex, phone, status, pageNum, pageSize);
        return result;
    }


    @PostMapping("auth/sysuser/update")
    @ApiOperation(value = "更新系统用户信息接口")
    @ApiImplicitParams({ @ApiImplicitParam(name = "sysUserId", required = true, value = "系统用户id"),
            @ApiImplicitParam(name = "email", required = false, value = "邮箱"),
            @ApiImplicitParam(name = "phone", required = false, value = "手机号"),
            @ApiImplicitParam(name = "address", required = false, value = "家庭地址"),
            @ApiImplicitParam(name = "faceUrl", required = false, value = "人脸照片"),
            @ApiImplicitParam(name = "status", required = false, value = "-1-删除，0-禁用，1-正常") })
    @ResponseBody
    public Result update(Long sysUserId, String name, String email, String phone, String address, String faceUrl,
                         StatusEnum status, HttpServletRequest request) {
        Result result = ssoApi.updateSysUser(sysUserId, email, phone, address, faceUrl, status);
        return result;
    }


    @ApiOperation(value = "添加系统人员信息")
    @ApiImplicitParams({ @ApiImplicitParam(name = "email", required = true, value = "邮箱"),
            @ApiImplicitParam(name = "name", required = true, value = "姓名"),
            @ApiImplicitParam(name = "password", required = true, value = "密码"),
            @ApiImplicitParam(name = "phone", required = true, value = "手机号"),
            @ApiImplicitParam(name = "sex", required = true, value = "-1-保密，0-男，1-女"),
            @ApiImplicitParam(name = "birth", required = true, value = "生日：yyyy-MM-dd"),
            @ApiImplicitParam(name = "address", required = true, value = "家庭地址"),
            @ApiImplicitParam(name = "faceUrl", required = true, value = "人脸照片"), })
    @PostMapping("auth/sysuser/add")
    public Result addSysUser(String name, String email, String password, String phone, SexEnum sex,
                             String birth,
                             String address, String faceUrl) {
        return ssoApi.addSysUser(email, phone, address, faceUrl, birth, password, sex, name);
    }


    @ApiOperation(value = "退出登录")
    @GetMapping("/logout")
    public Result logout() {
        return ssoApi.logout();
    }
}
